<template>
	<view class="container">
		<u-navbar left-icon="shopping-cart" left-icon-size="0" @leftClick="onClickLeft" title="My Cart"></u-navbar>
		<view class="list" :style="{marginTop: marginSwiperHeight}">
			<view class="list-header">
				<text class="all">MY CART LIST</text>
				<text class="delete">DELETE ALL</text>
			</view>
			<u-swipe-action>
				<u-swipe-action-item :options="options2" v-for="(item, index) in goodsList" :key="index">
					<view class="list-item">
						<image class="goods-img" :src="item.goodsImg" mode=""></image>
						<view class="goods-detail">
							<text class="goods-name"> {{ item.goodsName}}</text>
							<text class="goods-price"> {{ item.godsPrice}}</text>
							<u-number-box v-model="item.goodsCount" @change="valChange($event,index)"></u-number-box>
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				marginSwiperHeight: '', //导航栏高度
				count: 0, //商品计数器,
				goodsList: [{
						id: 1,
						goodsName: 'Sweatshirt',
						godsPrice: '$ 37',
						goodsImg: '../../../static/images/cart/goods1.png',
						goodsCount: '1'
					},
					{
						id: 2,
						goodsName: 'T-Shirt NB',
						godsPrice: '$ 125',
						goodsImg: '../../../static/images/cart/goods2.png',
						goodsCount: '3'
					},
					{
						id: 3,
						goodsName: 'Soft Touch Abaya',
						godsPrice: '$ 61',
						goodsImg: '../../../static/images/cart/goods3.png',
						goodsCount: '2'
					},
					{
						id: 4,
						goodsName: 'Solid Oxford',
						godsPrice: '$ 28',
						goodsImg: '../../../static/images/cart/goods4.png',
						goodsCount: '1'
					}
				],
				options2: [{
					icon: 'star',
					style: {
						backgroundColor: '#FFC107',
						fontSize: '50rpx',
					}
				}, {
					icon: 'trash',
					style: {
						backgroundColor: '#FF3D00',
						fontSize: '50rpx',
					}
				}],
			}
		},
		methods: {
			//导航栏的高度
			getBarHeight() {
				this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
				this.marginSwiperHeight = this.iStatusBarHeight + 44 + 'px';
				console.log(this.marginSwiperHeight);
			},
			//计数器
			valChange(e, index) { //值，下标
				this.goodsList[index].goodsCount = e.value;
			}
		},
		created() {
			this.getBarHeight();
		},
		onShow() {
			uni.pageScrollTo({
				scrollTop: 0, // 滚动到页面的目标位置（单位px）
				duration: 0 // 滚动动画的时长，默认300ms，单位 ms
			});
		}
	}
</script>

<style lang="scss">
	.list {

		padding: 44rpx;

		.list-header {
			display: flex;
			justify-content: space-between;

			.all {
				color: #515C6F;
				font-size: 26rpx;
			}

			.delete {
				color: #F0867F;
				font-size: 26rpx;
			}
		}

		.u-swipe-action-item {
			margin: 34rpx 0;
			border-radius: 16rpx;
		}

		.list-item {
			background-color: #fff;
			display: flex;

			.goods-img {
				width: 240rpx;
				height: 240rpx;
				border-radius: 16rpx;
				margin: 14rpx;
			}

			.goods-detail {
				display: flex;
				flex-direction: column;
				margin-left: 48rpx;

				text {
					padding: 7rpx;
				}

				.goods-name {
					color: #222B45;
					font-size: 32rpx;
					margin-top: 20rpx;
				}

				.goods-price {
					color: #65DACC;
					font-size: 32rpx;
				}

				.u-number-box {
					margin-top: 36rpx;
				}
			}
		}
	}
</style>